var res [][]int


func combinationSum(candidates []int, target int) [][]int {
    res = make([][]int, 0)
    backtracking(candidates, target, 0, 0, []int{})
    return res
}

func backtracking(candidates []int, target int, startIndex int,sum int, path []int){
    if sum == target {
        tem := make([]int, len(path))
        copy(tem, path)
        res = append(res, tem)
        return
    }
    if sum > target {
        return
    }
    for i:=startIndex; i<len(candidates); i++ {
        path = append(path, candidates[i])
        sum += candidates[i]
        backtracking(candidates, target, i, sum, path)
        path = path[:len(path)-1]
        sum -= candidates[i]
    }
}